﻿using System;
using System.Collections.Generic;
using System.Text;
using DAL.DateSet.GoodsRelatedTableAdapters;
using DAL.DateSet;
using DAL;
namespace BLL.Wrapper
{
    public class GoodsRelatedWrapper : GoodsRelatedTableAdapter
    {
        public GoodsRelated.GoodsRelatedDataTable getall()
        {
            return GetData();
        }

        public void addARecord(GoodsRelated.GoodsRelatedRow row)
        {
            Insert(row.colorID, row.modelID, row.goodsPrice, row.goodsCount, row.mapPicSrc, row.goodsPriceCreator, row.goodsPriceDate, row.goodsInstallFee, row.priceUnit, row.auxiliaryFee);
        }

        public void deleteByID(int id)
        {
            string sql = "delete from GoodsRelated where goodsRelatedID = " + id.ToString();
            HouseDiyHelper helper = HouseDiyHelper.GetInstance();
            helper.initOle();
            helper.delete(sql);
        }

        public void updateARecord(GoodsRelated.GoodsRelatedRow row)
        {
            GoodsRelated.GoodsRelatedDataTable table = GetData();
            for (int i = 0; i < table.Rows.Count; i++)
            {
                if (Convert.ToInt32(table.Rows[i]["goodsRelatedID"]) == row.goodsRelatedID)
                {
                    table.Rows[i]["colorID"] = row.colorID;
                    table.Rows[i]["modelID"] = row.modelID;
                    table.Rows[i]["goodsPrice"] = row.goodsPrice;
                    table.Rows[i]["goodsCount"] = row.goodsCount;

                    table.Rows[i]["mapPicSrc"] = row.mapPicSrc;
                    table.Rows[i]["goodsPriceCreator"] = row.goodsPriceCreator;
                    table.Rows[i]["goodsPriceDate"] = row.goodsPriceDate;
                    break;
                }
            }
            Update(table);
        }
    }
}
